#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

struct Edge {
    int x, y;
} E[] = {
        {1, 2},
        {1, 3},
        {1, 5},
        {2, 4},
        {4, 5},
        {5, 3}

};

int ind[6];
int n = 5, m = 6;
vector<int> res;

bool topsort() {
    int cnt = 0;
    //priority_queue<int, vector<int>, greater<int> > Q;
    queue<int> Q;
    for (int i = 1; i <= n; i++)
        if ( ind[i] == 0 ) {
            Q.push(i);
        }
    while (!Q.empty()) {
        int h = Q.front();//
        Q.pop();
        ++cnt;
        res.push_back(h);
        for (int i = 0; i < m; i++) {
            if ( E[i].x == h && --ind[E[i].y] == 0 )
                Q.push(E[i].y);
        }

    }
    return cnt == n;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (auto e:E) {
        ind[e.y]++;
    }
    copy(ind + 1, ind + 6, ostream_iterator<int>(cout, " "));
    cout << endl;

    if ( topsort()) {

        copy(res.begin(), res.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    } else {
        cout << "Not a DAG" << endl;
    }


    return 0;
}
